package com.leetcode.dp;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author Dennis Li
 * @date 2020/7/19 20:53
 */
public class FindLongestChain_646 {

    public int findLongestChain(int[][] pairs) {
        // 没有顺序要求，可以直接排序解题
        Arrays.sort(pairs, Comparator.comparingInt(o -> o[1]));
        int res = 1, tmp = pairs[0][1];
        for (int i = 1; i < pairs.length; i++) {
            if (pairs[i][0] > tmp) {
                res++;
                tmp = pairs[i][1];
            }
        }
        return res;
    }

}
